<template>
  <!-- 询价比详情 -->
  <div id="purchaseDetails">
    <div class="top">
      <van-nav-bar
        title="历史报价物资明细详情"
        left-arrow
        @click-left="$router.push('/viewHistoricalQuote')"
      />
    </div>
    <div class="msg" >
      <div class="company">
        报价公司名称:
        {{ msg.companyname }}
      </div>
      <div class="contact">
        <div>
          报价联系人:
          {{ msg.contact }}
        </div>
        <div>
          联系电话:
          {{ msg.contactphone }}
        </div>
      </div>
      <!-- <div>
        <div class="zzfj"> <div>资质附件：</div> <div style="color:blue"><p v-for="i in zzfj" :key="i.id">{{i.filename}} &nbsp;</p></div></div>
      </div> -->
    </div>
    <div class="nothing" v-show="list.length == 0">
      <p>暂无数据</p>
    </div>
    <div class="list-item" v-for="(item, index) in list" :key="index">
      <div>
        <p class="title">{{ item.wzmc }}</p>
      </div>
      <div class="row">
        <div>规格型号：{{ item.ggxh }}</div>
        <div>数量：{{ item.xqsl }}</div>
      </div>
      <div class="row">
        <div>计量单位：{{ item.jldw }}</div>
        <div>税率：{{  (item.sl * 1) * 100 }}%</div>
      </div>
      <div class="row">
        <div>到货地：{{ item.dhd }}</div>
        <div>预计交货期：{{ item.yjdhsj }}</div>
      </div>
      <div class="rows " >
        <div>实际交货期：{{ item.jhq }}</div>
        <!-- <calendar
 
          name="wtfwtrq"
          label="实际交货期"
          placeholder="请选择日期"
          class="entrustment mandatory"
          v-model="item.delivery"
        /> -->
      </div>
      <div>
        <div>备注：</div>
        <div>{{ item.remark }}</div>
      </div>
      <div>
        <p>质量要求：</p>
        <p class="quality">{{ item.zlyq }}</p>
        <div class="detail" @click="inQualityDetail(item.zlyq)">
          详情
        </div>
      </div>

      <div>
        <span class="theUnitPrice ">不含税单价：{{item.bj}} 元</span>
        <!-- <van-field
          class="inputN"
          type="number"
          placeholder="请输入金额"
          autocomplete="off"
          v-model="item.bj"
        /> -->
        <!-- <span class="money">元</span> -->
      </div>
      <div>
        <!-- 总价： <input type="text" v-model="item.zj" :value="(item.bj === ''||null||undefined ? 0 :(item.bj*1) * (item.quantityRequired*1))"> -->
        总价：<span ref="totalPrice">{{
          item.bj === "" || null || undefined
            ? 0
            : item.bj * 1 * (item.xqsl * 1)
        }}元</span>
        <!-- 总价：<span ref="totalPrice" >{{item.zj}}</span>  -->
      </div>
        <div style="color: red">
            <div>询价发布人:</div>
            <div>{{ publisher }}</div>
        </div>
    </div>
   
    <!-- <div class="submit" v-show="list.length > 0">
      <div class="row TPrice" v-show="!(list.length == 0)">
      <p >不含税合计总价：{{ this.allPrice }}</p>
      <p>含税合计总价：{{ ((this.allPrice)*1.13).toFixed(2) }}</p>
    </div>
      <van-button
        round
        block
        type="info"
        @click="submit"
        :loading="loading"
        :disabled="loading"
        >提交报价</van-button
      >
    </div> -->

  </div>
</template>

<script>
import { Toast } from "vant";
import api from "../../http/api";
export default {
  data() {
    return {
      whether: null,
      totalPrice: "22",
      // whether: true,
      theAmountOf: "", //输入的金额
      pattern: /^(([1-9]{1}\d*)|(0{1}))((.\d{0,2})?)$/, //数字和小数点
      code: "",
      loading: false,
      // 当前数据id
      id: null,
      // 列表数据
      noTaxPrice: "", //不含税总价
      //   taxPrice: "", //含税总价
      list: {},
      msg: {

      },
      // 资质附件
      file: [],
      fileName: [],
        publisher: ''
    };
  },
  mounted() {
    this.getDetail();
    // console.log('this.$refs.totalPrice :>> ', this.$refs.totalPrice.innerText);
  },
  computed: {
    allPrice() {
      return this.list.reduce((total, current) => {
        const price = Number(current.bj * (current.quantityRequired * 1));

        total += Number.isNaN(price) ? 0 : price;
        return total;
      }, 0);
    },
  },

  methods: {
    /**
     * 进入质量要求详情页面
     * @param {string} text 质量要求文本内容
     */
    inQualityDetail(text) {
      this.$router.push({
        name: "historicalQuoteDetail",
        params: {
          id: this.id,
          msg: text,
        },
      });
    },
    // 附件上传
    afterRead() {},
    // 获取详情信息
    getDetail() {
      Toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
      });
      this.id = this.$route.query.id;
      var id = this.$route.query.id;
            var phone = localStorage.phone //电话号码
            // var phone = "15181798337"
            api.purchase.quoteMaterialDetailed(phone,id).then((res)=>{
                Toast.clear();
                this.msg = res.data.data.data.supInformation;
                this.list = res.data.data.data.details;
                this.zzfj = res.data.data.data.gyszzfjList;
                this.publisher = res.data.data.data.publisher;
            })
   
    },
    /**
     * 提交报价
     */
    async submit() {
      this.loading = true;
      var res;

      if (this.file.length > 0) {
        let formData = new FormData();
        this.file.forEach((item) => {
          formData.append("file", item.file);
        });
        res = await api.file.upload(formData);
        if (res.data.code == 200) {
          this.fileName = res.data.data;
        }
      }
      var flage = true;
      // 判断报价是否为空
      for (var i = 0; i < this.list.length; i++) {
        if (
          this.list[i].bj == "" ||
          this.list[i].bj == undefined ||
          (this.list[i].bj == null && this.list[i].jhq == "") ||
          this.list[i].jhq == null ||
          this.list[i].jhq == undefined
        ) {
          flage = false;
        }
      }
      if (flage) {
        if (this.whether == "是" && this.fileName == "") {
          Toast.fail("请上传附件后在提交");
          this.loading = false;
        } else {
          api.purchase
            .submitPurchase({
              loginPhone: localStorage.phone, //手机号
              // loginPhone: "15181798337", //手机号
              data: this.list, //报价列表
              noTaxPrice: this.allPrice, //不含税总价
              taxPrice: (this.allPrice * 1.13).toFixed(2), //不含税总价
              accessory: this.fileName, //附件
              code: this.code, //询比价发布编码
              supplier: this.msg, //供应商信息
            })
            .then((res) => {
              this.loading = false;
              if (res.data.code == 200) {
                Toast.success("提交成功");
                setTimeout(() => {
                  this.$router.push("/purchase");
                }, 800);
              } else {
                Toast.fail("提交失败");
              }
            });
        }
      } else {
        Toast.fail("单价或交货期不能为空");
        this.loading = false;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.zzfj {
    display: flex;
    align-items: center;
    font-size: 14px;
    p{
        margin: 4px 0;
    }

}
.mandatory {
  position: relative;
  &::after {
    position: absolute;
    left: -12px;
    top: 4px;
    content: "*";
    color: red;
    font-size: 20px;
  }
}
#inputNum {
  border: 1px solid #eeeeee;
  outline: none;
  border-radius: 2px;
  padding: 0 0 0 13px;
  width: 100%;
  margin: 0 10px 0 0;
}
.rows {
  /deep/ .van-cell {
    background-color: #fff !important;
    border: none !important;
  }
}
#purchaseDetails {
  width: 100vw;
  min-height: calc(100vh);
  background-color: #f5f5f5;
//   padding-bottom: 132px;
  padding-top: 51px;
  box-sizing: border-box;
  position: relative;
  .nothing {
    color: #333;
    text-align: center;
    font-size: 16px;
  }
  .top {
    position: fixed;
    width: 100%;
    top: 0;
    overflow: hidden;
    background-color: white;
    z-index: 1;
  }
  & > .row {
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    background-color: #fff;
    box-sizing: border-box;
    margin: 10px;
    height: auto;
    p {
      white-space: pre-wrap !important;
      font-size: 16px;
    }
  }
  .list-item {
    margin: 8px 10px;
    background: #ffffff;
    border-radius: 8px;
    padding: 12px 16px;
    overflow: hidden;
    .title {
      font-family: "Inter";
      font-style: normal;
      font-weight: 600;
      font-size: 16px;
      line-height: 19px;
      margin-bottom: 12px;
      color: #333333;
    }
    .row {
      div {
        width: 50%;
        white-space: pre-wrap !important;
      }
    }
    & > div {
      font-family: "Inter";
      font-style: normal;
      font-weight: 400;
      font-size: 14px;
      line-height: 23px;
      color: #666666;
      margin: 0;
      display: flex;
      align-items: center;
      position: relative;
      min-height: 28px;
      line-height: 24px;
      & > div:nth-of-type(1),
      & > p:nth-of-type(1) {
        white-space: nowrap;
      }
      .theUnitPrice {
        margin-right: 10px;
        flex: 2;
      }
      .inputN {
        flex: 4;
      }
      .money {
        flex: 1;
      }
      p {
        margin: 0;
      }
      .quality {
        max-width: 56%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .detail {
        position: absolute;
        right: 0;
        width: auto;
        background: rgba(14, 134, 209, 0.2);
        border: 1px solid #0e86d1;
        border-radius: 5px;
        font-family: "ABeeZee";
        font-style: normal;
        font-weight: 400;
        font-size: 14px;
        height: 23px;
        line-height: 23px;
        padding: 0 10px;
        text-align: center;
        letter-spacing: -0.24px;
        color: #0e86d1;
      }
    }
  }
  .msg {
    background: #ffffff;
    padding: 12px;
    .company {
      font-family: "Inter";
      font-style: normal;
      font-weight: 600;
      font-size: 16px;
      line-height: 24px;
      /* identical to box height, or 150% */

      color: #333333;
    }
    .contact {
      margin-top: 10px;
      display: flex;
      font-family: "Inter";
      font-style: normal;
      font-weight: 400;
      font-size: 14px;
      /* identical to box height, or 143% */
      color: #666666;

      div {
        width: 50%;
      }
    }
  }
  .submit {
    padding: 10px;
    width: 100%;
    position: fixed;
    bottom: 0;
    height: 127px;
    box-sizing: border-box;
    background-color: white;
    & > .row {
      border-radius: 5px;
      display: flex;
      justify-content: space-between;
      padding: 0 10px;
      background-color: #fff;
      box-sizing: border-box;
      margin: 10px;
      height: auto;
      p {
        white-space: pre-wrap !important;
        font-size: 16px;
        margin: 5px 0;
      }
    }
    /deep/ .van-button--block {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      padding: 10px 143.5px;
      gap: 10px;
      background: #0e86d1;
      border-radius: 4px;
    }
  }
}

/deep/ .van-ellipsis {
  overflow: visible;
}
/deep/ .van-nav-bar__left {
  padding: 10px;
}
/deep/ .van-ellipsis {
  overflow: visible;
}
/deep/ .van-nav-bar__content {
  height: 51px;
}
/deep/ .van-nav-bar__title {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-size: 18px;
  line-height: 20px;
  /* identical to box height, or 111% */

  text-align: center;
  letter-spacing: -0.24px;

  color: #333333;
}
/deep/ .van-nav-bar .van-icon {
  /* 文字颜色3 */

  color: #999999;
}
/deep/ .van-cell {
  padding: 0;
  box-sizing: border-box;
  margin-right: 10px;
  background: rgba(243, 243, 243, 0.5);
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  line-height: 33px;
}
/deep/ .van-field__control {
  padding-left: 10px;
}
/deep/ .van-uploader__file-name {
  overflow: hidden;
  text-align: right;
}
/deep/ .van-uploader__input-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
/deep/ .van-uploader__file-icon {
  display: none;
}
/deep/ .van-uploader__file {
  width: auto;
  height: auto;
  background-color: transparent;
}
/deep/ .van-field__value {
  overflow: hidden;
}
/deep/ .van-uploader__preview,
/deep/ .van-uploader,
/deep/ .van-uploader__input-wrapper {
  width: 100%;
}
/deep/ .van-uploader__preview {
  margin: 0;
}
/deep/ .van-uploader__wrapper {
  padding: 5px;
}
/deep/ .van-uploader {
  background: rgba(14, 134, 209, 0.2);
  border: 1px solid #0e86d1;
  border-radius: 5px;
  font-family: "ABeeZee";
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
  line-height: 23px;
  /* identical to box height, or 143% */

  text-align: center;
  letter-spacing: -0.24px;

  color: #0e86d1;
  width: auto;
  max-width: 100%;
}
</style>
